package ThreadTest;

public class TestDemo3 {
    public static void main(String[] args) {
        Object object = new Object();//实例化一个Object类的对象
        Thread thread1 = new Thread(()->{
            synchronized (object) {
                System.out.println("thread1-开始");
                try {
                    object.wait();//thread1中调用wait方法
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("thread1-结束");
            }
        });//创建thread1线程
        thread1.start();//启动thread1线程

        Thread thread2 = new Thread(()->{
            synchronized(object) {
                System.out.println("thread2-开始");
                try {
                    object.wait();//thread2调用wait方法
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("thread2-结束");
            }
        });//创建thread2线程
        thread2.start();//启动thread2线程

        Thread thread3 = new Thread(()->{
            synchronized (object) {
                object.notify();//thread3中调用notifyAll方法
                System.out.println("thread3调用了notifyAll方法");
            }
        });//创建thread3线程
        thread3.start();//启动thread3线程
    }
}
